#!/usr/bin/python

import sys
import re
from Bio import SeqIO
from Bio.SeqRecord import SeqRecord

seqfile = sys.argv[1]
sfh = open(seqfile, "rU")
seq = SeqIO.read(sfh, "fasta")

coordfile = sys.argv[2]
cfh = open(coordfile, "rU")
cfl = cfh.readlines()

mask_region_starts = []
mask_region_stops = []
masked_seq = seq.seq.tomutable()

for line in cfl:
    l = line.split('\t')
    ltag = l[0]
    start = int(l[1])
    stop = int(l[2])
    strand = l[3]
    desc = l[4].rstrip()
    for x in range(start, stop):
        masked_seq[x] = "N"

#print masked_seq[1708384:1713676]

rec = SeqRecord(masked_seq, id=seq.id, description="(RNA coding regions masked)")

print rec.format('fasta')

sfh.close()
cfh.close()